package io.renren.modules.yckj.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.yckj.dao.AddressDao;
import io.renren.modules.yckj.dto.AddressDTO;
import io.renren.modules.yckj.entity.AddressEntity;
import io.renren.modules.yckj.service.AddressService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 发票管理
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2025-04-16
 */
@Service
public class AddressServiceImpl extends CrudServiceImpl<AddressDao, AddressEntity, AddressDTO> implements AddressService {

    @Override
    public QueryWrapper<AddressEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");
        String recipient = (String) params.get("recipient");
        String phone = (String) params.get("phone");
        String address = (String) params.get("address");

        Object userId = params.get("userId");


        QueryWrapper<AddressEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
        wrapper.eq(ObjectUtil.isAllNotEmpty(userId), "user_id", userId);
        wrapper.like(StrUtil.isNotBlank(recipient), "recipient", recipient);
        wrapper.like(StrUtil.isNotBlank(phone), "phone", phone);
        wrapper.like(StrUtil.isNotBlank(address), "address", address);


        return wrapper;
    }


    @Override
    public boolean updateIsDefaultNo(Long userId) {
        return baseDao.updateIsDefaultNo(userId);
    }
}